import java.awt.Graphics;
import java.awt.Image;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import javax.swing.JPanel;

public class Img extends JPanel{

	private static final long serialVersionUID = 1L;
	private Image tmp;
	private Image tmp2;
	private String img;
	private int coord_x;
	private int coord_y;
	private String comportement;
	private int width = DimensionSingleton.getInstance().getWidthImg();
	private int height = DimensionSingleton.getInstance().getHeightImg() ;

	public Img(ImageIcon i) {
		super();
	}

	public Img(String image, int _x, int _y, String _c) {
		super();
		this.coord_x = _x;
		this.coord_y = _y;
		this.comportement = _c;
		this.img = image;

		try {
			this.tmp = ImageIO.read(new File("images/" + img));
			this.tmp2 = ImageIO.read(new File("images/" + img));
		}
		catch (IOException exc) {
			exc.printStackTrace();
		}
	}

	public void ChangeImg(String image) {

		this.img = image;
		try {
			this.tmp = ImageIO.read(new File("images/" + img));
			this.tmp2 = ImageIO.read(new File("images/" + img));
		}
		catch (IOException exc) {
			exc.printStackTrace();
		}
	}

	public void setCoord_y(int _y) {
		this.coord_y = _y;
	}
	
	public int getCoord_y(){
		return this.coord_y;
	}
	
	public void setComportement(String _c){
		this.comportement = _c;			
	}

	public void paintComponent(Graphics g){
		super.paintComponent(g);
		g.drawImage(this.tmp, this.coord_x, this.coord_y, this.width, this.height, this);
		
		if (this.comportement == "descend"){
			g.drawImage(this.tmp2, this.coord_x, this.coord_y - height, this.width, this.height, this);
		}
		else{
			g.drawImage(this.tmp2, this.coord_x, this.coord_y + height, this.width, this.height, this);
		}
	}
}